package com.itheima.d4_collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/*
    目标：斗地主游戏的案例开发。
    业务需求分析:
        业务: 总共有54张牌。
        点数: "3","4","5","6","7","8","9","10","J","Q","K","A","2"
        花色: "♠", "♥", "♣", "♦"
        大小王: "👲" , "🃏"
        点数分别要组合4种花色，大小王各一张。
        斗地主：发出51张牌，剩下3张作为底牌。
 */
public class GameDemo {
    public static void main(String[] args) {
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] colors = {"♠", "♥", "♣", "♦"};

        int size = 0;
        ArrayList<Card> cards = new ArrayList();
        for (String number : numbers) {
            size++;
            for (String color : colors) {
                Card card  = new Card(number,color,size);
                cards.add(card);
            }
        }
        Card xiaowang = new Card("","🃏",++size);
        Card dawang = new Card("","👲" ,++size);
        Collections.addAll(cards,xiaowang,dawang);
        System.out.println(cards);

        System.out.println("洗牌后：");
        Collections.shuffle(cards);
        System.out.println(cards);

        ArrayList<Card> liubei = new ArrayList<>();
        ArrayList<Card> guanyu = new ArrayList<>();
        ArrayList<Card> zhangfei = new ArrayList<>();

//        liubei.addAll(cards.subList(0,16));
//        guanyu.addAll(cards.subList(17,33));
//        zhangfei.addAll(cards.subList(34,50));

        for (int i = 0; i < cards.size() -3; i++) {
            Card card = cards.get(i);
            if(i % 3 == 0){
                liubei.add(card);
            }else if(i % 3 ==1){
                guanyu.add(card);
            }else {
                zhangfei.add(card);
            }
        }


//        System.out.println("刘备："+liubei);
//        System.out.println("关羽："+guanyu);
//        System.out.println("张飞："+zhangfei);


        ArrayList<Card> dipai = new ArrayList<>();
        dipai.addAll(cards.subList(cards.size() - 3,cards.size()));
        System.out.println("底牌：" + dipai);

        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Collections.sort(liubei, (o1, o2) -> o2.getSize() - o1.getSize());
        Collections.sort(guanyu, (o1, o2) -> o2.getSize() - o1.getSize());
        Collections.sort(zhangfei, (o1, o2) -> o2.getSize() - o1.getSize());

//        Collections.sort(guanyu, new Comparator<Card>() {
//            @Override
//            public int compare(Card o1, Card o2) {
//                return o1.getSize() - o2.getSize();
//            }
//        });
//
//        Collections.sort(zhangfei, new Comparator<Card>() {
//            @Override
//            public int compare(Card o1, Card o2) {
//                return o1.getColor().compareTo(o2.getColor());
//            }
//        });

        System.out.println("刘备："+liubei);
        System.out.println("关羽："+guanyu);
        System.out.println("张飞："+zhangfei);

        liubei.addAll(dipai);
        Collections.sort(liubei,(o1, o2) -> o2.getSize() - o1.getSize());


        System.out.println("+++++++++++++++++++++++++抢地主后+++++++++++++++++++++++++++++++++++");
        System.out.println("刘备："+liubei);
        System.out.println("关羽："+guanyu);
        System.out.println("张飞："+zhangfei);

    }

}










